<template>
  <div class="container-pt">
    <van-nav-bar
      left-arrow
      @click-left="$router.back()"
      fixed
      title="我的点赞"
    />
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <article-list
        :disable-swiper="false"
        v-for="item in likeList"
        :key="item.id"
        :item="item"
      >
        <van-button
          square
          type="warning"
          text="取消"
          @click="cancel(item.id)"
        />
      </article-list>
    </van-list>
  </div>
</template>

<script>
import articleList from '@/components/article-list.vue'
import { getUserDataList, updateLike, } from '@/api/artice';
export default {
  components: { articleList },
  data() {
    return {
      active: 0,
      page: 1,
      limit: 10,
      loading: false,
      finished: false,
      likeList: []
    }
  },
  methods: {
    async onLoad() {
      const res = await getUserDataList({
        type: 2,
        page: this.page,
        limit: this.limit
      })
      this.loading = false
      this.page++
      // this.collectList = res.data.list.data
      if (this.page > res.data.list.totalPages) {
        this.finished = true
      }
      this.likeList.push(...res.data.list.data)
    },
    async cancel(id) {
      try {
        console.log(id)
        await updateLike({
          id: id,
          action: 'del'
        })
        this.$toast.success('操作成功！')
        this.page = 1
        this.likeList = []
        this.onLoad()
      } catch (error) {
        this.$toast.success('操作失败，请刷新后再次尝试！')
      }
    }
  }

}
</script>

<style>
</style>